package tankgame;

import javafx.application.Application;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @author: lizhiwen
 * @version: 1.0
 */
public class TankGameApp extends JFrame {
    //初始化排行榜画板
    RankingPanel rankingPanel = null;
    //初始化游戏画板
    MyPanel myPanel = null;

    public static void main(String[] args) {
        //先ui后游戏
        Application.launch(Ui.class,args);
        TankGameApp tankGameApp = new TankGameApp();
    }

    public TankGameApp() {
        if (!Controller.choice.equals("3")) {
            myPanel = new MyPanel(Controller.choice);
            //执行myPanel线程
            new Thread(myPanel).start();
            this.add(myPanel);
            //设置边界大小
            this.setSize(1700, 950);
            this.addMouseListener(myPanel);//监听鼠标事件
            this.addKeyListener(myPanel);//监听
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setVisible(true);
            //监听窗口关闭
            this.addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    Record.keepRecord();
                    Record.keepWallRecord();
                    System.exit(0);
                }
            });
        }

        //排行榜
        if (Controller.choice.equals("3")) {
            rankingPanel = new RankingPanel();
            this.add(rankingPanel);
            //设置边界大小
            this.setSize(1300, 950);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setVisible(true);
        }
    }
}
